<?php
namespace Wechat\Logic;

class EventLogic extends CommonLogic{
	
	public function detail($eventText,$uid){
		
	    $event = $this->where(array('event'=>$eventText,'uid'=>$uid))->field(true)->find();
	    
	    //如果是文本消息
	    if($event['msgtype'] == 'text'){
	    	
	    	$textmsgLogic = D('Textmsg','Logic');
	    	$textmsg = $textmsgLogic->detail($event['msgid']);
	    
	    	$data[] = $textmsg['text'];
	    	$data[] = 'text';
	    
	    	return $data;
	    }
	    
	    if( in_array($event['msgtype'], array('news','onenews'))){
	    	$map = array(
	    			'id'=>$event['msgid'],
	    	);
	    }else{
	    	if($event['msgtype'] == 'vips'){
	    	    $event['msgtype'] = 'clubcard';
	    	}
	    	$map = array(
	    			'relation'=>$event['msgtype'],
	    			'relationid'=>0,
	    	);
	    }
	    
	    $newsmsgLogic = D('Newsmsg','Logic');
	    	
	    $newsmsg = $newsmsgLogic->detail($map);
	    	
	    if($newsmsg['msgtype'] == 'onenews'){
	    	$data[][] = $newsmsg['configs'];
	    }else{
	    	$data[] = $newsmsg['configs'];
	    }
	    
	    $data[] = 'news';
	    
	    return $data;
	    	
	}
	
	/* !CodeTemplates.overridecomment.nonjd!
	 * @see \Wechat\Logic\BaseLogic::update()
	 */
	public function update($id = 0) {
		// TODO 自动生成的方法存根
		
	}

	/* !CodeTemplates.overridecomment.nonjd!
	 * @see \Wechat\Logic\BaseLogic::autoSave()
	 */
	public function autoSave($id = 0) {
		// TODO 自动生成的方法存根
		
	}
	
	
	/**
	 * 默认回复
	 */
	public function defaultReply($uid){
		$event = $this->where(array('event'=>'subscribe','uid'=>$uid))->field('id,arbitrarily')->find();
	
		if(!empty($event) && $event['arbitrarily'] == 1){
			return $this->detail('subscribe', $uid);
		}
	
	}

	
}